<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="peoit" tagdir="/WEB-INF/tags" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<peoit:include>

	<div class="pd-20">
		<form action="<c:url value="/admin/person/personAdd"/>" method="post" class="form form-horizontal" id="form-person-edit">
			<div class="row cl">
				<label class="form-label col-2"><span class="c-red">*</span>角色名称：</label>
				<div class="formControls col-10">
					<input type="text" class="input-text" value="${personDto1.name}"  placeholder="请输入角色名称"  name="name"  datatype="*" nullmsg="请输入管理员名称！">
				</div>
			</div>
			<div class="row cl">
				<label class="form-label col-2"><span class="c-red">*</span>管理员密码：</label>
				<div class="formControls col-10">
					<input type="password" class="input-text" placeholder="请输入管理员密码"  name="password"  plugin="passwordStrength" datatype="*4-16" nullmsg="请设置密码！" errormsg="密码范围在4~16位之间！">
				</div>
			</div>

			<div class="row cl">
				<label class="form-label col-2"><span class="c-red">*</span>确认密码：</label>
				<div class="formControls col-10">
					<input type="password" class="input-text" placeholder="确认密码"  name="password2"  datatype="*" recheck="password" nullmsg="请再输入一次密码！" errormsg="您两次输入的账号密码不一致！">
				</div>
			</div>
			<div class="row cl">
				<label class="form-label col-2"><span class="c-red">*</span>描述：</label>
				<div class="formControls col-10">
					<input type="text" class="input-text" value="${personDto1.description}" datatype="*"  placeholder="请输入描述" name="description">
					<input type="hidden" value="${personDto1.id}"  name="id">
				</div>
			</div>

			<div class="row cl">
				<label class="form-label col-2">选择角色：</label>
				<div class="formControls col-10">
					<c:forEach items="${viewData}" var="rolst">

						<dl class="permission-list">
							<dd>
								<dl class="cl permission-list2">
									<dt>

										<label class="">
											<input type="checkbox" value="${rolst.id}" datatype="need2"
											<c:forEach items="${personDto1.roles}" var="rolst2">
											 ${rolst2.id == rolst.id?"checked":""}
											</c:forEach>
										    name="roleIds"  id="user-Character-0-0">
												${rolst.description}
										</label>

									</dt>
								</dl>

							</dd>
						</dl>
					</c:forEach>
				</div>
			</div>
			<div class="row cl">
				<div class="col-10 col-offset-2">
					<button type="submit" class="btn btn-success radius" id="admin-role-save" name="admin-role-save"><i class="icon-ok"></i> 确定</button>
				</div>
			</div>
		</form>
	</div>

</peoit:include>
<script type="text/javascript">
	function refreshAndColse(){
		window.parent.location.href = window.parent.location;
	}
	$(function(){

		//表单验证ajax提交
		$("#form-person-edit").Validform({
			tiptype:3,
			datatype: {//传入自定义datatype类型【方式二】;
				"need2": function (gets, obj, curform, regxp) {
					var need = 1,
							numselected = curform.find("input[name='" + obj.attr("name") + "']:checked").length;
					return numselected >= need ? true : "请至少选择一项！";
				}
			},
			callback:function(form){
				$("#form-person-edit").ajaxSubFromDialog(this);
				setTimeout(refreshAndColse,1500);
				return false;
			}
		});

		$(".permission-list dt input:checkbox").click(function(){
			$(this).closest("dl").find("dd input:checkbox").prop("checked",$(this).prop("checked"));
		});
		$(".permission-list2 dd input:checkbox").click(function(){
			var l =$(this).parent().parent().find("input:checked").length;
			var l2=$(this).parents(".permission-list").find(".permission-list2 dd").find("input:checked").length;
			if($(this).prop("checked")){
				$(this).closest("dl").find("dt input:checkbox").prop("checked",true);
				$(this).parents(".permission-list").find("dt").first().find("input:checkbox").prop("checked",true);
			}
			else{
				if(l==0){
					$(this).closest("dl").find("dt input:checkbox").prop("checked",true);
				}
				if(l2==0){
					$(this).parents(".permission-list").find("dt").first().find("input:checkbox").prop("checked",true);
				}
			}

		});
	});
</script>
</body>
</html>